package com.maiji.cloud.service.impl;

import com.maiji.cloud.config.MyRedisConfig;
import com.maiji.cloud.entities.community.ComReport;
import com.maiji.cloud.entities.login.AppUser;
import com.maiji.cloud.mapper.ComReportMapper;
import com.maiji.cloud.microservice.UserInfoService;
import com.maiji.cloud.request.BaseInputDto;
import com.maiji.cloud.request.IdInputDto;
import com.maiji.cloud.request.community.ComReportInputDto;
import com.maiji.cloud.response.BaseOutPutDto;
import com.maiji.cloud.response.Status;
import com.maiji.cloud.service.ComReportService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.maiji.cloud.utils.RedisUtil;
import com.maiji.cloud.utils.TimeUtil;
import com.maiji.cloud.utils.UUID_MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2019-12-09
 */
@Service
@Transactional

public class ComReportServiceImpl extends ServiceImpl<ComReportMapper, ComReport> implements ComReportService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private UserInfoService userInfoService;

    public BaseOutPutDto<String> report(BaseInputDto<ComReportInputDto> inputDto, String maijiToken){
        BaseOutPutDto<String> baseOutPutDto = new BaseOutPutDto();
        try{

            AppUser appUser = RedisUtil.getAppUserByRedis(redisTemplate, MyRedisConfig.REDISDATABASENO, maijiToken, userInfoService);
            String userId = appUser.getUuId();
            ComReport report = new ComReport();
            report.setUuId(UUID_MD5.getUUID());
            report.setMsgId(inputDto.getData().getMsgId());
            report.setReportReason(inputDto.getData().getReportReason());
            report.setSourceUserId(userId);
            report.setReportTime(TimeUtil.getCurDateStamp());

            if(insert(report)){
                baseOutPutDto.setStatus(Status.SUCCESS);
                baseOutPutDto.setData("举报成功");
            }

        }catch (Exception exc){
            baseOutPutDto.setStatus(Status.ERROR);
            baseOutPutDto.setMessage("举报失败");
        }
        return baseOutPutDto;
    }

}
